<template>
  <view class="my-jobs-container">
    <!-- 顶部导航 -->
    <view class="header">
      <view class="back-button" @click="goBack">
        <image class="back-icon" src="/static/back.png"></image>
      </view>
      <text class="page-title">我的发布</text>
    </view>

    <!-- 岗位列表 -->
    <scroll-view scroll-y class="jobs-list-scroll">
      <view class="jobs-container">
        <view v-if="loading" class="loading">
          <view v-for="n in 3" :key="n" class="job-card skeleton">
            <view class="skeleton-line title"></view>
            <view class="skeleton-line company"></view>
            <view class="skeleton-line meta"></view>
          </view>
        </view>
        
        <view v-else-if="jobs.length === 0" class="empty-state">
          <text class="empty-icon">💼</text>
          <text class="empty-text">还没有发布任何岗位</text>
          <text class="empty-desc">快去发布第一个岗位吧</text>
          <button class="publish-btn" @click="goToPublish">发布岗位</button>
        </view>
        
        <view v-else class="jobs-list">
          <view v-for="(job, idx) in jobs" :key="idx" class="job-card" @click="goToJobDetail(job.id)">
            <view class="job-title-row">
              <text class="job-title">{{ job.title }}</text>
              <text class="job-salary">{{ job.salary }}</text>
            </view>
            <view class="job-company-row">
              <text class="company">{{ job.company }}</text>
              <text class="tag" v-for="(tag, i) in job.tags" :key="i">{{ tag }}</text>
            </view>
            <view class="job-meta">
              <text class="meta">{{ job.date }}</text>
              <text class="meta">{{ job.location }}</text>
              <text class="meta">{{ job.views }}看过</text>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      loading: true,
      jobs: []
    }
  },
  
  onLoad() {
    this.loadMyJobs()
  },
  
  methods: {
    goBack() {
      uni.navigateBack()
    },
    
    async loadMyJobs() {
      this.loading = true
      try {
        // 模拟接口调用
        // const response = await uni.request({
        //   url: '/api/my-jobs',
        //   method: 'GET'
        // })
        
        // 模拟数据
        await new Promise(resolve => setTimeout(resolve, 1000))
        
        this.jobs = [
          {
            id: 1,
            title: '前端开发工程师',
            salary: '15k-25k',
            company: '小红书',
            tags: ['React', 'Vue', '全栈'],
            date: '2024-01-15',
            location: '上海',
            views: 128
          },
          {
            id: 2,
            title: 'UI设计师',
            salary: '12k-18k',
            company: '小红书',
            tags: ['Figma', 'Sketch', '交互设计'],
            date: '2024-01-12',
            location: '北京',
            views: 89
          },
          {
            id: 3,
            title: '产品经理',
            salary: '20k-35k',
            company: '小红书',
            tags: ['B端产品', '数据分隔线析', '用户研究'],
            date: '2024-01-10',
            location: '深圳',
            views: 156
          }
        ]
      } catch (error) {
        console.error('获取我的发布失败:', error)
        uni.showToast({
          title: '获取数据失败',
          icon: 'none'
        })
      } finally {
        this.loading = false
      }
    },
    
    goToJobDetail(jobId) {
      uni.navigateTo({
        url: `/pages/recruit/job-detail?id=${jobId}`
      })
    },
    
    goToPublish() {
      uni.navigateTo({
        url: '/pages/recruit/publish-job'
      })
    }
  }
}
</script>

<style scoped>
.my-jobs-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f0f9f4 0%, #e8f5e8 100%);
}

/* 顶部导航 */
.header {
  position: relative; /* 为返回按钮提供定位上下文 */
  background: transparent;
  padding: 110rpx 36rpx 40rpx; /* 增加头部内边距，给标题更多空间 */
  color: #333333;
  display: flex;
  justify-content: center; /* 标题居中 */
  align-items: center;
}

.back-button {
  position: absolute;
  top: 98rpx; /* 与header新的padding-top对齐 */
  left: 36rpx; /* 与header的padding-left对齐 */
  z-index: 10;
  width: 64rpx;
  height: 64rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 185, 129, 0.15);
  border-radius: 50%;
  transition: all 0.3s ease;
  border: 1rpx solid rgba(16, 185, 129, 0.2);
}

.back-icon {
  width: 36rpx;
  height: 36rpx;
  opacity: 0.8;
  transition: opacity 0.3s ease;
  filter: brightness(0);
}

.back-button:hover {
  background: rgba(16, 185, 129, 0.25);
  border-color: rgba(16, 185, 129, 0.3);
}

.back-icon:active {
  opacity: 1;
}

.page-title {
  font-size: 36rpx;
  font-weight: 700;
  color: #333333;
  text-align: center;
  flex: 1;
}

.header-right {
  width: 64rpx;
}

/* 岗位列表 */
.jobs-list-scroll {
  height: calc(100vh - 160rpx);
  padding: 0 32rpx 24rpx;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.jobs-list-scroll::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.jobs-container {
  min-height: 100%;
}

.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}

/* 岗位卡片 - 简洁美观 */
.job-card {
  background: #fff;
  border-radius: 20rpx;
  box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.04);
  padding: 28rpx 24rpx;
  border: 1rpx solid #f5f5f5;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.job-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4rpx;
  height: 100%;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.job-card:hover::before {
  opacity: 1;
}

.job-card:hover {
  transform: translateY(-2rpx);
  box-shadow: 0 8rpx 24rpx rgba(0,0,0,0.08);
  border-color: rgba(16, 185, 129, 0.1);
}

.job-title-row {
  flex-direction: row;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16rpx;
}

.job-title {
  font-size: 32rpx;
  font-weight: 700;
  color: #222;
  flex: 1;
  margin-right: 16rpx;
}

.job-salary {
  color: #333333 !important;
  font-size: 32rpx;
  font-weight: normal !important;
}

.job-company-row {
  flex-direction: row;
  display: flex;
  align-items: center;
  margin-bottom: 16rpx;
}

.company {
  color: #666;
  font-size: 26rpx;
  margin-right: 16rpx;
}

.tag {
  background: rgba(16, 185, 129, 0.08);
  color: #10b981;
  font-size: 22rpx;
  padding: 8rpx 16rpx;
  border-radius: 16rpx;
  margin-right: 12rpx;
  font-weight: 500;
  border: 1rpx solid rgba(16, 185, 129, 0.1);
}

.job-meta {
  flex-direction: row;
  display: flex;
  align-items: center;
  gap: 16rpx;
}

.meta {
  color: #999;
  font-size: 24rpx;
}

/* 加载状态 */
.loading {
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}

.skeleton {
  background: #fff;
  border-radius: 24rpx;
  padding: 32rpx 24rpx;
}

.skeleton-line {
  height: 32rpx;
  background: linear-gradient(90deg, #f2f2f2 25%, #e6e6e6 37%, #f2f2f2 63%);
  background-size: 400% 100%;
  border-radius: 8rpx;
  animation: shimmer 1.5s infinite;
  margin-bottom: 16rpx;
}

.skeleton-line.title {
  width: 60%;
}

.skeleton-line.company {
  width: 40%;
}

.skeleton-line.meta {
  width: 80%;
  margin-bottom: 0;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* 空状态 - 简洁美观 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 120rpx 40rpx;
  text-align: center;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 24rpx;
  margin: 24rpx;
  backdrop-filter: blur(10rpx);
}

.empty-icon {
  font-size: 100rpx;
  margin-bottom: 32rpx;
  opacity: 0.7;
  filter: grayscale(0.3);
}

.empty-text {
  font-size: 32rpx;
  color: #333;
  font-weight: 600;
  margin-bottom: 12rpx;
}

.empty-desc {
  font-size: 26rpx;
  color: #666;
  margin-bottom: 48rpx;
  line-height: 1.5;
}

.publish-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  border: none;
  border-radius: 28rpx;
  padding: 20rpx 48rpx;
  font-size: 30rpx;
  font-weight: 600;
  box-shadow: 
    0 12rpx 32rpx rgba(16, 185, 129, 0.25),
    0 6rpx 16rpx rgba(16, 185, 129, 0.15);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  letter-spacing: 1rpx;
}

.publish-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.6s ease;
}

.publish-btn:hover::before {
  left: 100%;
}

.publish-btn:hover {
  transform: translateY(-3rpx);
  box-shadow: 
    0 16rpx 40rpx rgba(16, 185, 129, 0.35),
    0 8rpx 20rpx rgba(16, 185, 129, 0.25);
}

.publish-btn:active {
  transform: translateY(-1rpx) scale(0.98);
  box-shadow: 
    0 8rpx 24rpx rgba(16, 185, 129, 0.3),
    0 4rpx 12rpx rgba(16, 185, 129, 0.2);
}
</style>
